//
// Created by entaoyang@163.com on 2021/7/24.
//

import Foundation
import SwiftSweet


func testSQL() {
    testModel()

}

func testStudentInfo() {
    let ls = Student._table.sqlite.tableInfo("Student")
    for c in ls {
        logd("Column: ", c.name, c.type)
    }
    let a = Student._table.sqlite.indexList("Student")
    for d in a {
        logd("Index: ", d.name)
    }
}

func testModel() {
    Student._table.dropTable()
    Student._table.createTable()
    for i in 1...9 {
        let p = Student()
        p.name = "yang_\(i)"
        p.age = 30 + i
        p.insert()
    }
    Student.findAll().each {
        println($0)
    }
    logd("--------------")
    let p = Student.oneKey(9)!
    p.update {
        p.name = "Entao "
        p.age = 999
    }
    let pp = Student.oneKey(9)
    println(pp)
    logd("--------------")
}

@objcMembers
class Student: Model {

    dynamic var id: Int = 0
    dynamic var name: String = ""
    dynamic var age: Int = 0
    dynamic var male: Bool = false
    dynamic var addr: String = ""

    override class func onTableDefine(_ table: Table) {
        table["id"].PrimaryKey().AutoInc()
        table["name"].Index()
        table["age"].Index()
    }
}

